<?php require_once LAYOUTPATH.'layout_header.php'; ?>

<?php require_once APPPATH.'views/bricabox/header.php'; ?>

<div id="content_header">
	<div class="left">
		<h1><img class="profile_avatar" src="<?php echo url_for_avatar($mem_user->avatar, $mem_user->id, 'user', 'large'); ?>" alt="<?php echo $mem_user->login; ?>" width="100" height="100" />
			<a href="/member/<?php echo user_url($mem_user); ?>" title="Permalink to this member"><?php echo username($mem_user); ?></a>
		<h2><?php echo auto_typography(ascii_to_entities(auto_link($mem_user->bio, 'both', true))); ?>&nbsp;</h2>
	</div>
	<div class="right">
		<ul class="user_stats">
			<?php if ($this->userland->logged_in()): ?>
			
			
			<?php if ($mem_user->login != $user->login): ?>
				<li class="<?php echo $this->userland->is_following($mem_user->id) ? 'unfollow' : 'follow'; ?>">
					<a href="/follow/member/<?php echo user_url($mem_user); ?>">
						<?php echo $this->userland->is_following($mem_user->id) ? 'Unfollow' : 'Follow'; ?>
						<?php echo username($mem_user); ?></a></li>
			<?php else: ?>
			<li class="you"><span>This is you! <a href="/account/edit">Edit your account</a></span></li>
			<?php endif; ?>
			<?php endif; ?>
			<li class="member">Member since <?php echo date('m/d/Y', strtotime($mem_user->created_at)); ?></li>
			
			<?php if ($this->userland->logged_in() && $this->userland->current_user()->is_admin): ?>
			<a href="mailto:<?php echo $mem_user->email; ?>">Email</a>
			<?php endif; ?>
		</ul>
		
		
	</div>
</div>

<div id="blocks">
	<div class="column" id="blocks_large">
		<div class="activity_stream">
			<h3>
				<a id="tab_your" href="#" onclick="return Tabs.switchT('your');"><?php echo username($mem_user); ?>'s recent activity</a>
				<a id="tab_contacts" href="#" onclick="return Tabs.switchT('contacts');">Their contacts' recent activity</a>
				
			</h3>
			<div class="clearfix"></div>
			<div class="inner" id="your_activity">
				<ul>
				<?php
				if ($activity):
					foreach ($activity->result() as $activity_item):
				?>
					<li><?php echo activity_with_urls($activity_item, true); ?></li>
				<?php
					endforeach;
				endif;
				?>
				</ul>
			</div>
			<div class="inner" id="contacts_activity" style="display: none;">
				<ul>
				<?php
				if ($contactivity):
					foreach ($contactivity->result() as $activity_item):
				?>
					<li><?php echo activity_with_urls($activity_item); ?></li>
				<?php
					endforeach;
				endif;
				?>
				</ul>
			</div>
		</div>
		
		<script type="text/javascript" charset="utf-8">
			var Tabs = {
				switchT: function(name)
				{
					var el 		= $('#' + name + '_activity');
					var other 	= $('#' + (name == 'contacts' ? 'your' : 'contacts') + '_activity');
					
					el.show();
					other.hide();
					
					$('#tab_' + (name == 'contacts' ? 'your' : 'contacts')).removeClass('active');
					$('#tab_' + name).addClass('active');
					
					return false;
				}
			}
			Tabs.switchT('your');
		</script>
		
		<div class="clearfix">
			&nbsp;
		</div>
		
		<div class="comments">
			<?php require APPPATH.'views/account/_new_comment.php'; ?>
			
			<?php
			$COMMENT_USERS = array();
			if ($comments->num_rows()):
				foreach ($comments->result() as $comment):
			?>
			<?php require APPPATH.'views/account/_comment.php'; ?>
			<?php
				endforeach;
			endif;
			?>
		</div>
	</div>
	
	<div class="column" id="blocks_small">
		<div class="other_bricaboxes">
			<h2>My BricaBoxes</h2>
			<ul>
			<?php
			$query = $this->db->query('select subdomain,name,use_custom_domain,custom_domain from bricaboxes where user_id = ? and privacy > 0', array($mem_user->id));
			if ($query->num_rows()):
				foreach ($query->result() as $member_of):
			?>
				<li><a href="<?php echo bricabox_url($member_of); ?>"><?php echo $member_of->name; ?></a></li>
			<?php
				endforeach;
			endif;
			?>
			</ul>
		
			<h2>I'm a member of&hellip;</h2>
			<ul>
			<?php
			$query = $this->db->query('select subdomain,name,use_custom_domain,custom_domain from bricaboxes where privacy > 0 and id in (select bricabox_id from memberships where user_id = ? and role_id < 5)', array($mem_user->id));
			if ($query->num_rows()):
				foreach ($query->result() as $member_of):
			?>
				<li><a href="<?php echo bricabox_url($member_of); ?>"><?php echo $member_of->name; ?></a></li>
			<?php
				endforeach;
			endif;
			?>
			</ul>
			
			<h2>People I'm Following</h2>
			<?php if ($following->num_rows()): ?>
				<?php foreach ($following->result() as $followed_user): ?>
					<a rel="contact" style="float: left; border: none;" href="/member/<?php echo user_url($followed_user); ?>">
						<img class="profile_avatar" src="<?php echo url_for_avatar($followed_user->avatar, $followed_user->id, 'user', 'medium'); ?>" alt="<?php echo username($followed_user); ?>" <?php echo size_to_attrs('medium'); ?> /></a>
				<?php endforeach; ?>
			<?php endif; ?>
		</div>
	</div>
</div>

<?php require_once LAYOUTPATH.'layout_footer.php'; ?>